package com.boot.security.server.utils;

import io.swagger.models.auth.In;

/**
 * ${DESCRIPTION}
 *
 * @author chenzhongqiang
 * @create 2018-03-29 11:11
 **/
public class binarySearch {
    public static void main(String[] args) {
        int binary = binary(new Integer[]{2, 3, 4, 6, 8, 11,12,45,67,88,99,101,111,122,345,400}, 345);
        System.out.println(binary);
    }

    public static int binary(Integer[] array, int des) {
        int low = 0;
        int height = array.length - 1;
        while (low <= height) {
            int middle = (low + height) >>> 1;
            if (des == array[middle]) {
                return middle;
            } else if (des < array[middle]) {
                height = middle - 1;
            }else {
                low = middle + 1;
            }
        }
        return -1;
    }









}
